var sharedData = require("dataMgr");
//处理是否开启声音的脚本
cc.Class({
    extends: cc.Component,
    properties: {
        soundOn: {
            default: null,
            type: cc.SpriteFrame
        },
        soundOff: {
            default: null,
            type: cc.SpriteFrame
        }
    },
    // LIFE-CYCLE CALLBACKS:
    onLoad() {
        let tmp = cc.sys.localStorage.getItem("sound");
        if (tmp) {
            this._isPlaySound = tmp == 1;
        } else {
            this._isPlaySound = true;
        }
        sharedData.isPlaySound = this._isPlaySound;
        this._sprite = this.getComponent(cc.Sprite);
        this.setCurSpriteFrame();
        this.node.on(cc.Node.EventType.TOUCH_END, function (e) {
            this._isPlaySound = !this._isPlaySound;
            sharedData.isPlaySound = this._isPlaySound;
            cc.sys.localStorage.setItem("sound", this._isPlaySound ? 1 : 0);
            //这里保存一下这个值
            this.setCurSpriteFrame();
        }.bind(this), this);

        this.node.on(cc.Node.EventType.TOUCH_START, function (e) {
            e.stopPropagation();
            //开始点击的时候
        }.bind(this), this);

        this.node.on(cc.Node.EventType.TOUCH_MOVE, function (e) {
            e.stopPropagation();
            //开始点击的时候
        }.bind(this), this);

        this.node.on(cc.Node.EventType.TOUCH_CANCEL, function (e) {
            e.stopPropagation();
        }.bind(this), this);
    },

    setCurSpriteFrame: function () {
        if (this._isPlaySound) {
            this._sprite.spriteFrame = this.soundOn;
        } else {
            this._sprite.spriteFrame = this.soundOff;
        }
    },

    start() {

    },

    // update (dt) {},
});
